<?xml version="1.0" encoding="utf-8" ?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="Package">

  <!--
  	****************************************
  	* IMPORTS
	****************************************
  -->
  <PropertyGroup>
  	<MSBuildNuGetTasksPath>$(MSBuildProjectDirectory)\Tools\MSBuildNuGetTasks</MSBuildNuGetTasksPath>
  	<MSBuildExtensionsPath>$(MSBuildProjectDirectory)\Tools\MSBuildExtensions</MSBuildExtensionsPath>
  </PropertyGroup>

  <Import Project="$(MSBuildNuGetTasksPath)\MSBuild.NuGet.Tasks.Targets" />
  <Import Project="$(MSBuildExtensionsPath)\MSBuild.ExtensionPack.VersionNumber.targets"/>

  <!--
  	****************************************
  	* PROPERTIES
	****************************************
  -->

  <PropertyGroup>
	<PackageVersion>1.3</PackageVersion>
  </PropertyGroup>
  
  <PropertyGroup>
	<RootDir>$(MSBuildProjectDirectory)</RootDir>
	<BuildDir>$(RootDir)\Build</BuildDir>
	<PackageDir>$(RootDir)\Package</PackageDir>
	<ProjectDir>$(RootDir)\Src\CultivJupiterContactForm</ProjectDir>
	<ProjectName>CultivJupiterContactForm</ProjectName>
	<ViewsDir>Views\ContactFormSurface</ViewsDir>
  </PropertyGroup>

  <!--
  	****************************************
  	* TARGETS
	****************************************
  -->

  <!-- CLEAN -->
  <Target Name="Clean">
	<RemoveDir Directories="$(BuildDir)" Condition="Exists('$(BuildDir)')" />
  	<RemoveDir Directories="$(PackageDir)" Condition="Exists('$(PackageDir)')" />
	<MakeDir Directories="$(BuildDir)" />
  	<MakeDir Directories="$(PackageDir)" />
  </Target>

  <!-- VERSION -->
  <Target Name="Version" DependsOnTargets="Clean">
	<ItemGroup>
		<AssemblyInfoFile Include="$(ProjectDir)\Properties\AssemblyInfo.cs"/>
	</ItemGroup>
	<MSBuild.ExtensionPack.Framework.AssemblyInfo 
		AssemblyInfoFiles="@(AssemblyInfoFile)" 
		StartDate="1 Jan 2000" 
		AssemblyBuildNumberType="ElapsedDays" 
		AssemblyRevisionType="AutoIncrement"
		AssemblyRevisionFormat="000"
	/>
  </Target>

  <!-- COMPILE -->
  <Target Name="Compile" DependsOnTargets="Version">
	<MSBuild Projects="$(ProjectDir)\$(ProjectName).csproj" />
  </Target>
  
  <!-- PREPARE FILES -->
  <Target Name="PrepareFiles" DependsOnTargets="Compile">
    <ItemGroup>
      <BinFiles Include="$(ProjectDir)\Bin\Debug\$(ProjectName).dll" />
      <ViewFiles Include="$(ProjectDir)\$(ViewsDir)\*.cshtml" />
	  <PackageFile Include="$(RootDir)\Package.nuspec" />
    </ItemGroup>
	<Copy SourceFiles="$(ProjectDir)\web.config" DestinationFolder="$(BuildDir)\web.config" />
	<Copy SourceFiles="@(BinFiles)" DestinationFolder="$(BuildDir)\lib" />
	<Copy SourceFiles="@(ViewFiles)" DestinationFolder="$(BuildDir)\Views\Partial" />
	<Copy SourceFiles="$(ProjectDir)\Views\Web.config" DestinationFolder="$(BuildDir)\Views" />
	<Copy SourceFiles="@(PackageFile)" DestinationFolder="$(BuildDir)" />
  </Target>

  <!-- MANIFEST -->
  <Target Name="Manifest" DependsOnTargets="PrepareFiles">
	<ItemGroup>
      <ManifestFiles Include="$(BuildDir)\**\*" Exclude="$(BuildDir)\Package.nuspec" />
    </ItemGroup>
	<ManifestUpdate
		ManifestFile="$(BuildDir)\Package.nuspec"
		WorkingDirectory="$(BuildDir)"
		Version="$(PackageVersion)"
	    Files="@(ManifestFiles)" />
  </Target>

  <!-- PACKAGE -->
  <Target Name="Package" DependsOnTargets="Manifest">
	<Pack NuGetExePath="$(RootDir)\Tools\NuGet\NuGet.exe"
		ManifestFile="$(BuildDir)\Package.nuspec"
		BasePath="$(BuildDir)"
		OutputDirectory="$(PackageDir)"
		Verbose="true" />
  </Target>

</Project>